import request from "@/utils/request";
import type { ResponseData } from "@/api/user/type";
import type { TradeMarkResponseData } from "@/api/product/trademark/type";
import type { RoleUser } from "../user/type";
import type { MenuList } from "./type";
enum API {
  //获取全部角色职位分页列表
  ALLROLE_URL = "/admin/acl/role/",
  //新增角色职位
  ADDROLE_URL = "/admin/acl/role/save",
  //更新角色职位
  UPDATEROLE_URL = "/admin/acl/role/update",
  //删除角色职位
  REMOVEROLE_URL = "/admin/acl/role/remove/",
  //根据角色获取菜单
  ROLEMENU_URL = "/admin/acl/permission/toAssign/",
  //给角色分配权限
  SETPERMISSIONS_URL = "/admin/acl/permission/doAssign/?",
}
//获取全部角色职位分页列表
export const reqAllRolePosition = (
  page: number | string,
  limit: number | string,
  roleName: string
) => {
  return request.get<any, ResponseData<TradeMarkResponseData<RoleUser>>>(
    `${API.ALLROLE_URL}${page}/${limit}/?roleName=${roleName}`
  );
};
//新增|更新 角色职位
export const reqAddOrUpdateRolePosition = (data: RoleUser) => {
  if (data.id) {
    return request.put<any, any>(API.UPDATEROLE_URL, data);
  } else {
    return request.post<any, any>(API.ADDROLE_URL, data);
  }
};
//删除已有的角色职位
export const reqRemoveRolePosition = (id: number | string) => {
  return request.delete<any, any>(API.REMOVEROLE_URL + `${id}`);
};
//根据角色获取菜单
export const reqRoleMenu = (roleId: number | string) => {
  return request.get<any, ResponseData<MenuList[]>>(
    API.ROLEMENU_URL + `${roleId}`
  );
};
//给角色分配权限
export const reqSetPermissions = (roleId: number, permissionId: number[]) => {
  return request.post<any, any>(
    API.SETPERMISSIONS_URL + `roleId=${roleId}&permissionId=${permissionId}`
  );
};
